package com.kinglone.controller;

import java.awt.Desktop;
import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kinglone.model.CommBookModel;
import com.kinglone.service.CommBookService;
import com.kinglone.util.JSONMessageView;

@Controller
@RequestMapping("/ydjcbusiness/commbook")
public class CommBookController {

	@Autowired
	private CommBookService commBookServcie;
	
	/**
	 * 预览pdf
	 * @param request
	 * @return
	 */
	@RequestMapping("/openCommBook.jspx")
	@ResponseBody
	public JSONMessageView openCommBook(HttpServletRequest request){
		JSONMessageView msg=new JSONMessageView(-1,"查询失败",null);
		try {
			//String TASK_ID = request.getParameter("TASK_ID");
			String TASK_ID ="1111";
			CommBookModel commbookInfo = commBookServcie.queryById(TASK_ID);
			String path = commBookServcie.createPDF(request,commbookInfo);
 			Desktop.getDesktop().open(new File(path));
			msg.setCode(0);
			msg.setMessage("success");
		} catch (Exception e) {
			e.printStackTrace();
			msg.setMessage("预览失败!");
			msg.setCode(-1);
			msg.setMessage("error");
		}
		return msg;
	
	}
}
